package com.dudu.utils;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

public class SendMessageResult {
    private String messageType;
    private JsonElement data;
    private SendMessageResult sendMessageResult;
    public SendMessageResult(String message) {
        Gson gson = new Gson();
        sendMessageResult = gson.fromJson(message, getClass());
    }

    public <T> T getData(Class<T> clazz){
        Gson gson = new Gson();
        return gson.fromJson(sendMessageResult.data, clazz);
    }

    public <T> List<T> getDataList(Class<T> clazz){
        Gson gson = new Gson();
        Type type = TypeToken.getParameterized(List.class, clazz).getType();
        return gson.fromJson(sendMessageResult.data, type);
    }

    public String getMessageType() {
        return sendMessageResult.messageType;
    }
}
